Imports XL.Common
Imports XL.Common.Utils

Public Class S_01_00403        
    Inherits XL.DB.Utils.BaseService
    Public Shared Function GetInstance() As S_01_00403                                           
                                                                                                 
        Dim result As S_01_00403                                                                 
        If AssetVisionXAuto.Decls.CURRENT_DB_TYPE = XL.DB.DBDecl.DBType.Remoting Then

            result = CType(Activator.GetObject(GetType(S_01_00403), _
                String.Format("tcp://{0}/S_01_00403.remote", _
                    SysInfo.ReadLocalSysInfo(CommDecl.XLSLVN_SYSTEM_REMOTE_SERVICE_URL))),  _
                S_01_00403)

            If result.ValidateAuthPassword(CommDecl.CURRENT_LOCAL_REMOTE_AUTH_PASSWORD) = False Then
                Dim ex As New XLException(XLException.ErrorClassify.ReadDataError)
                ex.SetMessage(CommDecl.MSG_ALERT_REMOTE_AUTH_DENIED)
                Throw ex
            End If

        Else

            result = New S_01_00403
        End If

        Return result

    End Function

    Public Enum LCs
        None
        Utld0002
        Utld0003
        Utld0004
        Utld0005
    End Enum


    Public Function ServSaveInfo( _
        ByVal valStaffID As String, _
        ByVal valStaffCode As String, _
        ByVal valStaffName As String, _
        ByVal valLoginDeny As Boolean, _
        ByVal valMobilePhone As String, _
        ByVal valEmail As String, _
        ByVal valRemark As String, _
        ByVal valIsDimission As Boolean, _
        ByVal valDepartmentID As String, _
        ByVal valPhotoMark As String, _
        ByVal valSequreID As String _
        ) As String

        Try


            If valStaffID.Length = 0 Then

                Dim staffCondition As New AssetVisionXAuto.Facade.AfBizMaster.ConditionOfM_AV_STAFF(XL.DB.Utils.Condition.LogicOperators.Logic_And)
                staffCondition.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_STAFFColumns.STAFF_CODEColumn, "=", valStaffCode)
                If AssetVisionXAuto.Facade.AfBizMaster.GetM_AV_STAFFCount(staffCondition) > 0 Then
                    Return AssetVisionXService.Decls.MSG_STATUS_0047
                End If

                Dim staffID As String = System.Guid.NewGuid.ToString
                AssetVisionXAuto.Facade.AfBizMaster.CreateM_AV_STAFFInfo( _
                    valDepartmentID, _
                    valEmail, _
                    valIsDimission, _
                    valLoginDeny, _
                    valMobilePhone, _
                    CommTK.StringToImage(valPhotoMark), _
                    valRemark, _
                    valStaffCode, _
                    staffID, _
                    valStaffName, _
                    String.Empty)


            Else

                Dim staffCondition = New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_M_AV_STAFF(XL.DB.Utils.Condition.LogicOperators.Logic_And)
                staffCondition.Add(AssetVisionXAuto.Facade.AfXV.XV_M_AV_STAFFColumns.STAFF_IDColumn, "=", valStaffID)
                Dim staffRow = AssetVisionXAuto.Facade.AfXV.GetXV_M_AV_STAFFRow(staffCondition)
                If IsNothing(staffRow) = True Then
                    Return Decls.MSG_ALERT_00002
                End If

                If valDepartmentID <> staffRow.DEPARTMENT_ID Then

                    If staffRow.STAFF_ID = staffRow.PRINCIPAL Then
                        Return Decls.MSG_ALERT_00045
                    End If

                End If

                AssetVisionXAuto.Facade.AfBizMaster.ReviseM_AV_STAFFInfo( _
                    valStaffID, _
                    valDepartmentID, _
                    valEmail, _
                    valIsDimission, _
                    valLoginDeny, _
                    valMobilePhone, _
                    CommTK.StringToImage(valPhotoMark), _
                    valRemark, _
                    valStaffCode, _
                    valStaffName, _
                    Nothing)

            End If

            AssetVisionXService.Facade.OpBizMaster.SynchronizeStaffWithUser()
            Dim userCondition As New AssetVisionXAuto.Facade.AfSysConfig.ConditionOfS_USER(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            userCondition.Add(AssetVisionXAuto.Facade.AfSysConfig.S_USERColumns.USER_ACCOUNTColumn, "=", valStaffCode)
            AssetVisionXAuto.Facade.AfSysConfig.ReviseS_USERData(userCondition, AssetVisionXAuto.Facade.AfSysConfig.S_USERColumns.SECURE_IDColumn, valSequreID)

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServLoadInfo( _
        ByVal valStaffID As String, _
        ByRef refStaffRowSE As AssetVisionXAuto.FTs.FT_XV_M_AV_STAFFRowSEntity, _
        ByRef refUserRowSE As AssetVisionXAuto.FTs.FT_S_USERRowSEntity _
        ) As String
        Try


            Dim staffConditions As New AssetVisionXAuto.Facade.AfXV.ConditionOfXV_M_AV_STAFF(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            staffConditions.Add(AssetVisionXAuto.Facade.AfXV.XV_M_AV_STAFFColumns.STAFF_IDColumn, "=", valStaffID)

            AssetVisionXAuto.Facade.AfXV.FillXV_M_AV_STAFFRowSEntity(refStaffRowSE, staffConditions)

            If refStaffRowSE.IsNull = True Then
                Return AssetVisionXService.Decls.MSG_ALERT_00002
            End If

            Dim userCondition As New AssetVisionXAuto.Facade.AfSysConfig.ConditionOfS_USER(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            userCondition.Add(AssetVisionXAuto.Facade.AfSysConfig.S_USERColumns.USER_ACCOUNTColumn, "=", refStaffRowSE.STAFF_CODE)
            AssetVisionXAuto.Facade.AfSysConfig.FillS_USERRowSEntity(refUserRowSE, userCondition)


        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServLoadDepartmentByCode( _
       ByVal valDepartmentCode As String, _
       ByRef refDepartmentRowSE As AssetVisionXAuto.FTs.FT_M_AV_DEPARTMENTRowSEntity _
       ) As String

        Try


            Dim departmentConditions As New AssetVisionXAuto.Facade.AfBizMaster.ConditionOfM_AV_DEPARTMENT(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            departmentConditions.Add(AssetVisionXAuto.Facade.AfBizMaster.M_AV_DEPARTMENTColumns.DEPARTMENT_CODEColumn, "=", valDepartmentCode)

            AssetVisionXAuto.Facade.AfBizMaster.FillM_AV_DEPARTMENTRowSEntity(refDepartmentRowSE, departmentConditions)

            If refDepartmentRowSE.IsNull = True Then
                Return AssetVisionXService.Decls.MSG_ALERT_00002
            End If
            'Dim servResult As String = _
            '    Me._service.ServUtld0005(

            'If servResult.length > 0 Then
            '    Return servResult
            'End If

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServResetPassword( _
        ByVal valStaffCode As String _
        ) As String

        Try


            Dim sUserConditions As New AssetVisionXAuto.Facade.AfSysConfig.ConditionOfS_USER(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            sUserConditions.Add(AssetVisionXAuto.Facade.AfSysConfig.S_USERColumns.USER_ACCOUNTColumn, "=", valStaffCode)

            Dim sUserRow As AssetVisionXAuto.FTs.FT_S_USERRow = _
                AssetVisionXAuto.Facade.AfSysConfig.GetS_USERRow(sUserConditions)

            AssetVisionXAuto.Facade.AfSysConfig.ReviseS_USERRow(sUserRow.USER_ID, AssetVisionXAuto.Facade.AfSysConfig.S_USERColumns.USER_PASSWORDColumn, valStaffCode)

            'Dim servResult As String = _
            '    Me._service.ServUtld0004(

            'If servResult.length > 0 Then
            '    Return servResult
            'End If

        Catch ex As XL.Common.Utils.XLException

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)

            'WinTK.OutputLog("XL Exception", logContentBuilder.ToString())

            Return logContentBuilder.ToString()

        Catch ex As Exception

            Dim logContentBuilder As New LineStrBuilder
            logContentBuilder.AppendLine("Message: {0}", ex.Message)
            logContentBuilder.AppendLine("Stack Trace: {0}", ex.StackTrace)


            Return logContentBuilder.ToString()

        End Try

        Return String.Empty

    End Function


    Public Function ServBizUtld0005( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0005(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0006( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0006(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0007( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0007(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0008( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0008(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0009( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0009(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0010( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0010(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0011( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0011(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0012( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0012(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0013( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0013(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0014( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0014(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0015( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0015(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0016( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0016(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0017( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0017(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0018( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0018(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0019( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0019(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


    Public Function ServBizUtld0020( _
        ByVal valParaUtld As String, _
        ByRef refParaUtld As String _
        ) As String



        'Dim servResult As String = _
        '    Me._service.ServUtld0020(

        'If servResult.length > 0 Then
        '    Return servResult
        'End If

        Return String.Empty

    End Function


End Class
